/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Mark Vismonte
 * Started: 5/20/08
 * 
 */
package gamefiles;

import java.util.ArrayList;
import java.awt.Color;

public class Board extends Object
    {
    public Board()
        {
        super();
        rows = makeRowsSubCol(
                Coordinate.getArrayList(xMin, xMax, yMin, yMax, MAX_SIDES));
//        gLib = new CSAGraphicLib();
        local = new StrategoPlayer(IS_LOCAL_PLAYER);
        netBuddy = new StrategoPlayer(IS_NETWORK_PLAYER);
        lakes = StrategoLake.lakeCoors(this);
        }
    /* ArrayList of 10 arraylists
     * The arraylists all of 10 coordinates which correspond to the column
     * Example call: rows.get(2).get(5)
     * This will get the element at row 2 and column 5
     */
    private ArrayList<ArrayList<Coordinate>> makeRowsSubCol(
            ArrayList<Coordinate> input)
        {
        int numRows = input.size() / 10;
        ArrayList<ArrayList<Coordinate>> row = 
                new ArrayList<ArrayList<Coordinate>>(numRows);
        for (int i = 0; i < MAX_SIDES; i++)
            {
            ArrayList<Coordinate> col = new ArrayList<Coordinate>(MAX_SIDES);
            for (int x = 0; x < MAX_SIDES; x++)
                col.add(input.remove(0));
            row.add(col);
            }
        return row;
        }
    public void coordinateTest()
        {
        ArrayList<Coordinate> col = null;
        Coordinate here = null;
        for (int i = 0, box = 0; i < rows.size(); i++)
            {
            col = rows.get(i);
            for (int x = 0; x < col.size(); x++, box++)
                {
                here = col.get(x);
                CSAGraphicLib.setPenColor(Color.GREEN);
                CSAGraphicLib.fillCircle(here.getX(), here.getY(), 
                        FINAL_RAD);
                CSAGraphicLib.setPenColor(Color.BLACK);
                CSAGraphicLib.drawString(here.getX() - FINAL_RAD, here.getY(), 
                        "Circle: " + box);
                }
            }
        }
    public void drawBoard()
        {
        CSAGraphicLib.initLib();
        drawLakes();
        CSAGraphicLib.setPenWidth(3);
        CSAGraphicLib.setPenColor(Color.BLACK);
        //Take from the original Stratego board project
        for (int i = -(CSAGraphicLib.getHeight()/2);
        i <= CSAGraphicLib.getHeight()/2; i += 60)
                CSAGraphicLib.drawLine(-CSAGraphicLib.getHeight()/2
                        , i, CSAGraphicLib.getHeight()/2, i);
        for (int i = -(CSAGraphicLib.getWidth()/2); 
        i <= CSAGraphicLib.getWidth()/2; i += 60)
                CSAGraphicLib.drawLine(i, -CSAGraphicLib.getWidth()/2
                        , i, CSAGraphicLib.getWidth()/2);
        CSAGraphicLib.setPenWidth(1);
        }
    private void drawLakes()
        {
        for (StrategoLake lake: lakes)
            lake.draw();
        }
    public void drawCoor(int row, int col)
        {
        Coordinate dr = getCoordinate(row, col);
        CSAGraphicLib.drawCircle(dr.getX(), dr.getY(), FINAL_RAD);
        }
    public void drawCoor(Coordinate dr)
        {
        CSAGraphicLib.drawCircle(dr.getX(), dr.getY(), FINAL_RAD);
        }
    public void setPenColor(Color c)
        {
        CSAGraphicLib.setPenColor(c);
        }
    public Coordinate getCoordinate(int row, int col)
        {
        return rows.get(row).get(col);
        }
    public void setLocalPlayer(StrategoPlayer me)
        {
        local = me;
        }
    public void setNetworkPlayer(StrategoPlayer him)
        {
        netBuddy = him;
        }
    public StrategoPlayer getLocalPlayer()
        {
        return local;
        }
    public StrategoPlayer getNetworkPlayer()
        {
        return netBuddy;
        } 
    //Data Members
    private ArrayList<ArrayList<Coordinate>> rows;
    private ArrayList<StrategoLake> lakes;
    private StrategoPlayer local;
    private StrategoPlayer netBuddy;
    public static final int yMin = -300;
    public static final int yMax = 300;
    public static final int xMin = -300;
    public static final int xMax = 300;
    public static final int MAX_SIDES = 10;
    public static final int FINAL_RAD = 30;
    public static final boolean IS_LOCAL_PLAYER = true;
    public static final boolean IS_NETWORK_PLAYER = false;
    }
